package org.smog.core.config.security.hander;

import org.smog.core.exception.ForbiddenException;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 安全框架无权限处理
 *
 * @Description: Created by IntelliJ IDEA.
 * @project_name: smogTemp
 * @time: 2020-05-14 11:10
 * @email: 17685306043@163.com
 * @author: huangZhongYao
 */
@Component
public class JwtAuthenticationEntryPoint implements AuthenticationEntryPoint {
    @Override
    public void commence(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AuthenticationException e) throws IOException, ServletException {
        ForbiddenException forbidden = new ForbiddenException("Forbidden");
        httpServletResponse.sendError(forbidden.getCode(),forbidden.getMessage());
    }
}
